package ru.cod.rs.views;

import ru.cod.rs.managers.GameManager;
import android.content.Context;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

/**
 * Main View
 * 
 * @author Suslov Vadim
 * 
 */
public class GameView extends SurfaceView implements SurfaceHolder.Callback {
	private GameManager manager = null;

	public GameView(Context context) {
		super(context);
		getHolder().addCallback(this);
	}

	// /////////////////////////////////////////////

	@Override
	public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
		// TODO Auto-generated method stub

	}

	@Override
	public void surfaceCreated(SurfaceHolder arg0) {
		manager = new GameManager(getContext(), this);
		manager.setReady(true);
		manager.start();

	}

	@Override
	public void surfaceDestroyed(SurfaceHolder arg0) {
		manager.setReady(false);
		boolean b = true;
		while (b) {
			try {
				manager.join();
				b = false;
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		manager = null;
	}

}
